package mytest;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.servicediscovery.ServiceDiscovery;
import io.vertx.servicediscovery.ServiceDiscoveryOptions;
import io.vertx.servicediscovery.ServiceReference;

/**
 * @Author Ldj
 * @Date 2017/11/2 9:30
 * @Description 数据处理
 */
public class jq extends AbstractVerticle {
    @Override
    public void start(){



        ServiceDiscovery discovery = ServiceDiscovery.create(vertx,
                new ServiceDiscoveryOptions()
                        .setAnnounceAddress("service-announce")
                        .setName("my-name"));
        //consuming a service
        discovery.getRecord(r -> r.getName().equals("some-rest-api-2"), ar -> {
            if (ar.succeeded()) {
                if (ar.result() != null) {
                    // Retrieve the service reference
                    ServiceReference reference = discovery.getReference(ar.result());
                    // Retrieve the service object
                    HttpClient client = reference.get();
                    System.out.println("Consuming some-rest-api-2");

                    client.getNow("/", response -> {
                        //release the service
                        reference.release();

                    });
                }
                else {
                    System.out.println("error");
                }
            }
        });
    }
    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx();
        vertx.deployVerticle(jq.class.getName());
    }
}
